package com.eddy.liveline.user.service;

import com.eddy.liveline.core.spring.mybatis.pagehelper.Table;
import com.eddy.liveline.requirement.pojo.Requirement;
import com.eddy.liveline.user.pojo.Account;
import com.eddy.liveline.user.dao.AccountMapper;
import com.eddy.liveline.user.pojo.AccountTableQuery;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class AccountServiceImpl implements AccountService {

  @Resource
  private AccountMapper accountMapper;

  @Override
  public boolean batchSave(List<Account> accounts) {
    return accountMapper.batchSave(accounts);
  }

  @Override
  public boolean deleteById(String id) {
    return accountMapper.deleteById(id);
  }

  @Override
  public boolean deleteByIds(List<String> ids) {
    return accountMapper.deleteByIds(ids);
  }

  @Override
  public Account getById(String id) {
    return accountMapper.getById(id);
  }

  @Override
  public Table<Account> query(AccountTableQuery query) {
    Page<Object> page = PageHelper.startPage(query.getPageNumber(), query.getPageSize(), true);
    List<Account> list = accountMapper.query(query);
    return new Table<Account>(page.getTotal(), list);
  }

  @Override
  public boolean batchUpdate(List<Account> accounts) {
    return accountMapper.batchUpdate(accounts);
  }
}
